home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Draw / Sources / TextShp.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  6.9 KB  |  268 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                TextShp.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef BASESHP_H
  15. #include "BaseShp.h"
  16. #endif
  17.  
  18. #ifndef BOUNDSHP_H
  19. #include "BoundShp.h"
  20. #endif
  21.  
  22. #ifndef TEXTSHP_H
  23. #include "TextShp.h"
  24. #endif
  25.  
  26. #ifndef UTILS_H
  27. #include "Utils.h"
  28. #endif
  29.  
  30. #ifndef CONSTANT_H
  31. #include "Constant.h"
  32. #endif
  33.  
  34. #ifndef DRAWPART_H
  35. #include "DrawPart.h"
  36. #endif
  37.  
  38. #ifndef DRAWPART_H
  39. #include "DrawPart.h"
  40. #endif
  41.  
  42. #ifndef DRAWFRM_H
  43. #include "DrawFrm.h"
  44. #endif
  45.  
  46. #ifndef DRAWPRXY_H
  47. #include "DrawPrxy.h"
  48. #endif
  49.  
  50. #ifndef DRAWLINK_H
  51. #include "DrawLink.h"
  52. #endif
  53.  
  54. #ifndef DRAWCLIP_H
  55. #include "DrawClip.h"
  56. #endif
  57.  
  58. // ----- Part Layer -----
  59.  
  60. #ifndef FWFRMING_H
  61. #include "FWFrming.h"
  62. #endif
  63.  
  64. #ifndef FWUTIL_H
  65. #include "FWUtil.h"
  66. #endif
  67.  
  68. #ifndef FWSELECT_H
  69. #include "FWSelect.h"
  70. #endif
  71.  
  72. #ifndef FWITERS_H
  73. #include "FWIters.h"
  74. #endif
  75.  
  76. // ----- OS Layer -----
  77.  
  78. #ifndef FWEVENT_H
  79. #include "FWEvent.h"
  80. #endif
  81.  
  82. #ifndef FWRECSHP_H
  83. #include "FWRecShp.h"
  84. #endif
  85.  
  86. #ifndef FWTXTBOX_H
  87. #include "FWTxtBox.h"
  88. #endif
  89.  
  90. #ifndef FWLINSHP_H
  91. #include "FWLinShp.h"
  92. #endif
  93.  
  94. #ifndef FWOVLSHP_H
  95. #include "FWOvlShp.h"
  96. #endif
  97.  
  98. #ifndef FWRRCSHP_H
  99. #include "FWRRcShp.h"
  100. #endif
  101.  
  102. #ifndef FWODGEOM_H
  103. #include "FWODGeom.h"
  104. #endif
  105.  
  106. // ----- Foundation Includes -----
  107.  
  108. #ifndef FWSTREAM_H
  109. #include "FWStream.h"
  110. #endif
  111.  
  112. // ----- OpenDoc Includes -----
  113.  
  114. #ifndef SOM_ODTransform_xh
  115. #include <Trnsform.xh>
  116. #endif
  117.  
  118. //========================================================================================
  119. // Runtime Information
  120. //========================================================================================
  121.  
  122. #ifdef FW_BUILD_MAC
  123. #pragma segment odfdrawshapes
  124. #endif
  125.  
  126. //========================================================================================
  127. // RunTime Info
  128. //========================================================================================
  129.  
  130. FW_DEFINE_AUTO(CTextShape)
  131. FW_DEFINE_CLASS_M1(CTextShape, CBoundedShape)
  132.  
  133. const FW_ClassTypeConstant LTextShape = FW_TYPE_CONSTANT('s','h','t','x');
  134. FW_REGISTER_ARCHIVABLE_CLASS(LTextShape, CTextShape, CTextShape::Read, 0, 0, CBaseShape::Write)
  135.  
  136. //========================================================================================
  137. // class CTextShape
  138. //========================================================================================
  139.  
  140. //----------------------------------------------------------------------------------------
  141. // CTextShape::CTextShape
  142. //----------------------------------------------------------------------------------------
  143.  
  144. CTextShape::CTextShape() :
  145.     CBoundedShape(kTextShape, kFrameOnly),
  146.     fText
  147. (
  148. "\"Young man\", said the Russian playwright Anton Chekhov, "
  149. "\"I see a brilliant future written on your face.\" "
  150. "These words were spoken to Serge Rachmaninoff."
  151. )
  152. {
  153.     FW_END_CONSTRUCTOR
  154. }
  155.  
  156. //----------------------------------------------------------------------------------------
  157. // CTextShape::CTextShape
  158. //----------------------------------------------------------------------------------------
  159.  
  160. CTextShape::CTextShape(FW_CReadableStream& archive) :
  161.     CBoundedShape(archive)
  162. {
  163.     archive >> fText;
  164.     FW_END_CONSTRUCTOR
  165. }
  166.  
  167. //----------------------------------------------------------------------------------------
  168. // CTextShape::~CTextShape
  169. //----------------------------------------------------------------------------------------
  170.  
  171. CTextShape::~CTextShape()
  172. {
  173.     FW_START_DESTRUCTOR
  174. }
  175.  
  176. //----------------------------------------------------------------------------------------
  177. // CTextShape::RenderShape
  178. //----------------------------------------------------------------------------------------
  179.  
  180. void CTextShape::RenderShape(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc)
  181. {
  182.     // Draw a frame
  183.     FW_CRect rect = GetRectGeometry();
  184.     AdjustRectForPenSize(rect, GetPenSize());
  185.  
  186.     if (HasFrameStyle())
  187.         FW_CRectShape::RenderRect(gc, rect, FW_kFrame, fFrameInk, fFrameStyle);
  188.  
  189.     // Draw the text
  190.     FW_CFont font(FW_kTimes, FW_kPlain, FW_IntToFixed(12));
  191.  
  192.     rect.Inset(FW_IntToFixed(2), FW_IntToFixed(2));
  193.     FW_TextBoxOptions options = FW_kTextBoxJustifyHCenter | FW_kTextBoxWordWrap | FW_kTextBoxWordBreak | FW_kTextBoxClipToBox;
  194.     FW_CTextBoxShape::RenderTextBox(gc, fText, rect, font, options, fFrameInk);
  195. }
  196.  
  197. //----------------------------------------------------------------------------------------
  198. // CTextShape::HitTest
  199. //----------------------------------------------------------------------------------------
  200.  
  201. FW_Boolean CTextShape::HitTest(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent) const
  202. {
  203.     FW_CPoint mouse = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  204.     ODFacet* facet = theMouseEvent.GetFacet(ev);
  205.     FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  206.     frame->GetContentView(ev)->FrameToViewContent(ev, mouse);
  207.     
  208.     FW_CTextBoxShape textShape(fText, GetRectGeometry());
  209.     return textShape.HitTest(gc, mouse, FW_IntToFixed(2));
  210. }
  211.  
  212. //----------------------------------------------------------------------------------------
  213. // CTextShape::OutlineShape
  214. //----------------------------------------------------------------------------------------
  215.  
  216. void CTextShape::OutlineShape(FW_CGraphicContext& gc, const FW_CInk& ink, const FW_CStyle& style, const FW_CRect& rect)
  217. {
  218.     FW_CRectShape::RenderRect(gc,
  219.                               rect,
  220.                               FW_kFrame,
  221.                               ink, style);
  222. }
  223.  
  224. //----------------------------------------------------------------------------------------
  225. // CTextShape::GetClipRegion
  226. //----------------------------------------------------------------------------------------
  227.  
  228. void CTextShape::GetClipRegion(Environment *ev, ODShape* clipRegion)
  229. {
  230.     FW_CRect odRect = GetRectGeometry();
  231.     clipRegion->SetRectangle(ev, (ODRect*)&odRect);
  232. }
  233.  
  234. //----------------------------------------------------------------------------------------
  235. // CTextShape::CreateShapeOutline
  236. //----------------------------------------------------------------------------------------
  237.  
  238. ODShape* CTextShape::CreateShapeOutline(Environment *ev)
  239. {
  240.     // We don't acquire it because we return it
  241.     ODShape* dragRgn = ::FW_NewODShape(ev, GetRectGeometry());
  242.  
  243.     ::FW_OutlineODShape(ev, dragRgn, GetPenSize());
  244.  
  245.     return dragRgn;
  246. }
  247.  
  248. //----------------------------------------------------------------------------------------
  249. // CTextShape::Flatten
  250. //----------------------------------------------------------------------------------------
  251.  
  252. void CTextShape::Flatten(FW_CWritableStream& archive)
  253. {    
  254.     CBoundedShape::Flatten(archive);
  255.     archive << fText;
  256. }
  257.  
  258. //----------------------------------------------------------------------------------------
  259. // CTextShape::Read
  260. //----------------------------------------------------------------------------------------
  261.  
  262. void* CTextShape::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  263. {
  264. FW_UNUSED(type);
  265.     return FW_NEW(CTextShape, (stream));
  266. }
  267.  
  268.